﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing.plaf.basic {
    import org.aswing.*;
    import org.aswing.geom.*;
    import org.aswing.plaf.*;
    import flash.text.*;
    import org.aswing.event.*;
    import org.aswing.graphics.*;
    import org.aswing.util.*;

    public class BasicProgressBarUI extends BaseComponentUI {

        protected var iconDecorator:GroundDecorator;
        protected var stringText:TextField;
        protected var stateListener:Object;
        protected var progressBar:JProgressBar;
        protected var barSize:int;

        public function BasicProgressBarUI(){
            this.barSize = 12;
        }
        protected function getPropertyPrefix():String{
            return ("ProgressBar.");
        }
        override public function installUI(_arg1:Component):void{
            this.progressBar = JProgressBar(_arg1);
            this.installDefaults();
            this.installComponents();
            this.installListeners();
        }
        override public function uninstallUI(_arg1:Component):void{
            this.progressBar = JProgressBar(_arg1);
            this.uninstallDefaults();
            this.uninstallComponents();
            this.uninstallListeners();
        }
        protected function installDefaults():void{
            var _local1:String = this.getPropertyPrefix();
            LookAndFeel.installColorsAndFont(this.progressBar, _local1);
            LookAndFeel.installBasicProperties(this.progressBar, _local1);
            LookAndFeel.installBorderAndBFDecorators(this.progressBar, _local1);
            this.barSize = getInt((_local1 + "barWidth"));
            if (this.barSize == -1){
                this.barSize = 1000;
            };
            if (!this.progressBar.isIndeterminateDelaySet()){
                this.progressBar.setIndeterminateDelay(getUint((_local1 + "indeterminateDelay")));
                this.progressBar.setIndeterminateDelaySet(false);
            };
        }
        protected function uninstallDefaults():void{
            LookAndFeel.uninstallBorderAndBFDecorators(this.progressBar);
        }
        protected function installComponents():void{
            this.stringText = new TextField();
            this.stringText.autoSize = TextFieldAutoSize.CENTER;
            this.stringText.mouseEnabled = false;
            this.stringText.tabEnabled = false;
            this.stringText.selectable = false;
            this.progressBar.addChild(this.stringText);
        }
        protected function uninstallComponents():void{
            if (this.stringText.parent != null){
                this.stringText.parent.removeChild(this.stringText);
            };
            this.stringText = null;
            this.iconDecorator = null;
        }
        protected function installListeners():void{
            this.progressBar.addEventListener(InteractiveEvent.STATE_CHANGED, this.__stateChanged);
        }
        protected function uninstallListeners():void{
            this.progressBar.removeEventListener(InteractiveEvent.STATE_CHANGED, this.__stateChanged);
        }
        protected function __stateChanged(_arg1:JProgressBar):void{
            _arg1.repaint();
        }
        override public function paint(_arg1:Component, _arg2:Graphics2D, _arg3:IntRectangle):void{
            super.paint(_arg1, _arg2, _arg3);
            var _local4:JProgressBar = JProgressBar(_arg1);
            if (((!((_local4.getString() == null))) && ((_local4.getString().length > 0)))){
                this.stringText.text = _local4.getString();
                AsWingUtils.applyTextFontAndColor(this.stringText, _local4.getFont(), _local4.getForeground());
                if (_local4.getOrientation() == JProgressBar.VERTICAL){
                    this.stringText.rotation = -90;
                    this.stringText.x = Math.round((_arg3.x + ((_arg3.width - this.stringText.width) / 2)));
                    this.stringText.y = Math.round(((_arg3.y + ((_arg3.height - this.stringText.height) / 2)) + this.stringText.height));
                } else {
                    this.stringText.rotation = 0;
                    this.stringText.x = Math.round((_arg3.x + ((_arg3.width - this.stringText.width) / 2)));
                    this.stringText.y = Math.round((_arg3.y + ((_arg3.height - this.stringText.height) / 2)));
                };
                DepthManager.bringToTop(this.stringText);
            } else {
                this.stringText.text = "";
            };
        }
        override protected function paintBackGround(_arg1:Component, _arg2:Graphics2D, _arg3:IntRectangle):void{
        }
        override public function getPreferredSize(_arg1:Component):IntDimension{
            var _local3:IntDimension;
            var _local4:IntDimension;
            var _local2:JProgressBar = JProgressBar(_arg1);
            if (_local2.getOrientation() == JProgressBar.VERTICAL){
                _local3 = this.getPreferredInnerVertical();
            } else {
                _local3 = this.getPreferredInnerHorizontal();
            };
            if (_local2.getString() != null){
                _local4 = _arg1.getFont().computeTextSize(_local2.getString(), false);
                if (_local2.getOrientation() == JProgressBar.VERTICAL){
                    _local3.width = Math.max(_local3.width, _local4.height);
                    _local3.height = Math.max(_local3.height, _local4.width);
                } else {
                    _local3.width = Math.max(_local3.width, _local4.width);
                    _local3.height = Math.max(_local3.height, _local4.height);
                };
            };
            return (_local2.getInsets().getOutsideSize(_local3));
        }
        override public function getMaximumSize(_arg1:Component):IntDimension{
            return (IntDimension.createBigDimension());
        }
        override public function getMinimumSize(_arg1:Component):IntDimension{
            return (_arg1.getInsets().getOutsideSize(new IntDimension(1, 1)));
        }
        protected function getPreferredInnerHorizontal():IntDimension{
            return (new IntDimension(80, this.barSize));
        }
        protected function getPreferredInnerVertical():IntDimension{
            return (new IntDimension(this.barSize, 80));
        }

    }
}//package org.aswing.plaf.basic 
